package com.quanshu.shop.person.custom;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.quanshu.exchange.R;
import com.quanshu.exchange.support.utils.RxViewHelper;
import com.quanshu.shop.person.entity.MySelectAddressEntity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者  李哲
 * 创建时间 2018/8/3
 * 邮箱 lizhetongliao@163.com
 * 说明
 **/
public class DeleteAddressDialog extends Dialog {
    @BindView(R.id.delete_txt1)
    TextView deleteTxt1;
    @BindView(R.id.line1)
    View line1;
    @BindView(R.id.line2)
    View line2;
    @BindView(R.id.delete_txtCancel)
    TextView deleteTxtCancel;
    @BindView(R.id.delete_txtOk)
    TextView deleteTxtOk;
    private Context mContext;
    private OnDeleteAddressListener onDeleteAddressListener;
    private int position;
    private MySelectAddressEntity mySelectAddressEntity;

    public DeleteAddressDialog(Context context) {
        super(context, R.style.CartDialogWindow);
        mContext = context;
    }

    public void show(int position1,MySelectAddressEntity mySelectAddressEntity1) {
        position=position1;
        mySelectAddressEntity=mySelectAddressEntity1;
        super.show();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_delete_address);
        ButterKnife.bind(this);
        setCancelable(true);//点击外部不可dismiss
        setCanceledOnTouchOutside(true);
        Window window = this.getWindow();
        window.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
        initView();
    }

    private void initView() {
        RxViewHelper.getInstance().clicks(deleteTxtCancel, aVoid ->
                {
                    if (onDeleteAddressListener!=null){
                        onDeleteAddressListener.isDelete(false,position,mySelectAddressEntity);
                        dismiss();
                    }
                }

        );
        RxViewHelper.getInstance().clicks(deleteTxtOk, aVoid ->
                {
                    if (onDeleteAddressListener!=null){
                        onDeleteAddressListener.isDelete(true,position,mySelectAddressEntity);
                        dismiss();
                    }
                }

        );
    }


    public DeleteAddressDialog setOnDeleteAddressListener(OnDeleteAddressListener onDeleteAddressListener1) {
        onDeleteAddressListener = onDeleteAddressListener1;
        return this;
    }

    public interface OnDeleteAddressListener {
        void isDelete(boolean i,int position2,MySelectAddressEntity mySelectAddressEntity2);
    }
}
